<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta name="Content-Type" content="text/html; charset=UTF-8" />
<title>Module: MasterMayI::ControllerExtensions::InstanceMethods</title>
<link rel="stylesheet" href="../../css/style.css" type="text/css" media="screen" charset="utf-8" />
<link rel="stylesheet" href="../../css/common.css" type="text/css" media="screen" charset="utf-8" />

<script type="text/javascript" charset="utf-8">
  relpath = '../..';
  if (relpath != '') relpath += '/';
</script>
<script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="../../js/app.js"></script>

  </head>
  <body>
    <div id="header">
      <div id="menu">
  
    <a href="../../_index.html">Index (I)</a> &raquo; 
    <a href="../../MasterMayI.html" title="MasterMayI">MasterMayI</a> &raquo; <a href="../ControllerExtensions.html" title="ControllerExtensions">ControllerExtensions</a>
     &raquo; 
    <span class="title">InstanceMethods</span>
  
</div>

      <div id="search">
  <a id="class_list_link" href="#">Namespace List</a>
  <a id="method_list_link" href="#">Method List</a>
  <a id ="file_list_link" href="#">File List</a>
</div>

      <div class="clear"></div>
    </div>
    
    <iframe id="search_frame"></iframe>
    
    <div id="content"><h1>Module: MasterMayI::ControllerExtensions::InstanceMethods 
  
  
</h1>

<dl class="box">
  
  
    
  
    
  
  
    <dt class="r1 last">Defined in:</dt>
    <dd class="r1 last">lib/master_may_i/controller_extensions.rb</dd>
  
</dl>
<div class="clear"></div>

<h2>Overview</h2><div class="docstring">
  <div class="discussion">
    <p>
Helper methods added to your controller, which are required by
protects_restful_actions
</p>


  </div>
</div>
<div class="tags">
  
</div>


  <h2>Method Summary</h2>
  <ul class="summary">
    
      <li class="public ">
  <span class="summary_signature"><a href="#included-class_method" title="included (class method)">+ (Object) <strong>included</strong>(controller) </a>
  
  </span>
  
  
  
  

  
    <span class="summary_desc"></span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature"><a href="#current_user-instance_method" title="#current_user (instance method)">- (Object) <strong>current_user</strong> </a>
  
  </span>
  
  
  
  

  
    <span class="summary_desc">
Returns the currently logged in user.

</span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature"><a href="#current_user_session-instance_method" title="#current_user_session (instance method)">- (Object) <strong>current_user_session</strong> </a>
  
  </span>
  
  
  
  

  
    <span class="summary_desc">
Returns the current UserSession.

</span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature"><a href="#deny_access-instance_method" title="#deny_access (instance method)">- (Object) <strong>deny_access</strong>(opts = {}) </a>
  
  </span>
  
  
  
  

  
    <span class="summary_desc">
All before filters eventually call deny_access.

</span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature"><a href="#logged_in%3F-instance_method" title="#logged_in? (instance method)">- (Object) <strong>logged_in?</strong> </a>
  
  </span>
  
  
  
  

  
    <span class="summary_desc">
Returns whether or not there is a currently logged in user.

</span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature"><a href="#permission_denied_flash_for_user-instance_method" title="#permission_denied_flash_for_user (instance method)">- (Object) <strong>permission_denied_flash_for_user</strong> </a>
  
  </span>
  
  
  
  

  
    <span class="summary_desc">
Used by deny_access.

</span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature"><a href="#permission_denied_flash_for_visitor-instance_method" title="#permission_denied_flash_for_visitor (instance method)">- (Object) <strong>permission_denied_flash_for_visitor</strong> </a>
  
  </span>
  
  
  
  

  
    <span class="summary_desc">
Used by deny_access.

</span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature"><a href="#permission_denied_redirect_for_user-instance_method" title="#permission_denied_redirect_for_user (instance method)">- (Object) <strong>permission_denied_redirect_for_user</strong> </a>
  
  </span>
  
  
  
  

  
    <span class="summary_desc">
Used by deny_access.

</span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature"><a href="#permission_denied_redirect_for_visitor-instance_method" title="#permission_denied_redirect_for_visitor (instance method)">- (Object) <strong>permission_denied_redirect_for_visitor</strong> </a>
  
  </span>
  
  
  
  

  
    <span class="summary_desc">
Used by deny_access.

</span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature"><a href="#redirect_back_or-instance_method" title="#redirect_back_or (instance method)">- (Object) <strong>redirect_back_or</strong>(url) </a>
  
  </span>
  
  
  
  

  
    <span class="summary_desc">
Works in conjunction with store_location.

</span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature"><a href="#require_user-instance_method" title="#require_user (instance method)">- (Object) <strong>require_user</strong> </a>
  
  </span>
  
  
  
  

  
    <span class="summary_desc">
A before filter which calls deny_access if there isn&#8217;t a currently
logged in user.

</span>
  
</li>

    
      <li class="public ">
  <span class="summary_signature"><a href="#store_location-instance_method" title="#store_location (instance method)">- (Object) <strong>store_location</strong> </a>
  
  </span>
  
  
  
  

  
    <span class="summary_desc">
Used by deny_access and redirect_back_or to store and later redirect to the
currently requested location.

</span>
  
</li>

    
  </ul>



  <div id="method_details">
    <h2>Method Details</h2>
    
      <div class="method_details first">
  <p class="signature first" id="included-class_method">
  
    + (<tt>Object</tt>) <strong>included</strong>(controller) 
  

  
</p><div class="docstring">
  <div class="discussion">
    

  </div>
</div>
<div class="tags">
  
</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


52
53
54</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/master_may_i/controller_extensions.rb', line 52</span>

<span class='def def kw'>def</span> <span class='self self kw'>self</span><span class='dot token'>.</span><span class='included identifier id'>included</span><span class='lparen token'>(</span><span class='controller identifier id'>controller</span><span class='rparen token'>)</span>
  <span class='controller identifier id'>controller</span><span class='dot token'>.</span><span class='helper_method identifier id'>helper_method</span> <span class='symbol val'>:current_user_session</span><span class='comma token'>,</span> <span class='symbol val'>:current_user</span><span class='comma token'>,</span> <span class='symbol val'>:logged_in?</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="current_user-instance_method">
  
    - (<tt>Object</tt>) <strong>current_user</strong> 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>
Returns the currently logged in user
</p>


  </div>
</div>
<div class="tags">
  
</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


63
64
65
66</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/master_may_i/controller_extensions.rb', line 63</span>

<span class='def def kw'>def</span> <span class='current_user identifier id'>current_user</span>
  <span class='return return kw'>return</span> <span class='@current_user ivar id'>@current_user</span> <span class='if if_mod kw'>if</span> <span class='defined? defined kw'>defined?</span><span class='lparen token'>(</span><span class='@current_user ivar id'>@current_user</span><span class='rparen token'>)</span>
  <span class='@current_user ivar id'>@current_user</span> <span class='assign token'>=</span> <span class='current_user_session identifier id'>current_user_session</span> <span class='andop op'>&amp;&amp;</span> <span class='current_user_session identifier id'>current_user_session</span><span class='dot token'>.</span><span class='user identifier id'>user</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="current_user_session-instance_method">
  
    - (<tt>Object</tt>) <strong>current_user_session</strong> 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>
Returns the current UserSession
</p>


  </div>
</div>
<div class="tags">
  
</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


57
58
59
60</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/master_may_i/controller_extensions.rb', line 57</span>

<span class='def def kw'>def</span> <span class='current_user_session identifier id'>current_user_session</span>
  <span class='return return kw'>return</span> <span class='@current_user_session ivar id'>@current_user_session</span> <span class='if if_mod kw'>if</span> <span class='defined? defined kw'>defined?</span><span class='lparen token'>(</span><span class='@current_user_session ivar id'>@current_user_session</span><span class='rparen token'>)</span>
  <span class='@current_user_session ivar id'>@current_user_session</span> <span class='assign token'>=</span> <span class='UserSession constant id'>UserSession</span><span class='dot token'>.</span><span class='find identifier id'>find</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="deny_access-instance_method">
  
    - (<tt>Object</tt>) <strong>deny_access</strong>(opts = {}) 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>
All before filters eventually call deny_access. deny_access stores the
current location in the session, sets the flash and redirects the user.
</p>
<p>
The flash, and where the user is redirected to are chosen based on whether
there is a logged in user, and are customizeable by overriding the
permission_denied_flash_for_user permission_denied_redirect_for_user
permission_denied_flash_for_visitor and
permission_denied_redirect_for_visitor methods
</p>


  </div>
</div>
<div class="tags">
  
  
    
    
    <h3>Options Hash (<tt>opts</tt>):</h3>
    <ul class="option">
      
        <li>
          <span class="type">(<tt>String</tt>)</span>
          <span class="name">:flash</span>
          <span class="default">
            
              &mdash; default:
              <tt>permission_denied_flash_for_visitor or permission_denied_flash_for_user</tt>
            
          </span>
          &mdash;
Flash message displayed after redirect.


        </tr>
      
        <li>
          <span class="type">(<tt>String</tt>)</span>
          <span class="name">:redirect_to</span>
          <span class="default">
            
              &mdash; default:
              <tt>permission_denied_redirect_for_visitor or permission_denied_redirect_for_user</tt>
            
          </span>
          &mdash;
URL the user is redirected to.


        </tr>
      
    </ul>
  

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


93
94
95
96
97
98
99
100
101
102
103
104
105</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/master_may_i/controller_extensions.rb', line 93</span>

<span class='def def kw'>def</span> <span class='deny_access identifier id'>deny_access</span><span class='lparen token'>(</span><span class='opts identifier id'>opts</span> <span class='assign token'>=</span> <span class='lbrace token'>{</span><span class='rbrace token'>}</span><span class='rparen token'>)</span>
  <span class='if if kw'>if</span> <span class='logged_in? fid id'>logged_in?</span>
    <span class='opts identifier id'>opts</span><span class='lbrack token'>[</span><span class='symbol val'>:flash</span><span class='rbrack token'>]</span>       <span class='opasgn op'>||=</span> <span class='permission_denied_flash_for_user identifier id'>permission_denied_flash_for_user</span>
    <span class='opts identifier id'>opts</span><span class='lbrack token'>[</span><span class='symbol val'>:redirect_to</span><span class='rbrack token'>]</span> <span class='opasgn op'>||=</span> <span class='permission_denied_redirect_for_user identifier id'>permission_denied_redirect_for_user</span>
  <span class='else else kw'>else</span>
    <span class='opts identifier id'>opts</span><span class='lbrack token'>[</span><span class='symbol val'>:flash</span><span class='rbrack token'>]</span>       <span class='opasgn op'>||=</span> <span class='permission_denied_flash_for_visitor identifier id'>permission_denied_flash_for_visitor</span>
    <span class='opts identifier id'>opts</span><span class='lbrack token'>[</span><span class='symbol val'>:redirect_to</span><span class='rbrack token'>]</span> <span class='opasgn op'>||=</span> <span class='permission_denied_redirect_for_visitor identifier id'>permission_denied_redirect_for_visitor</span>
  <span class='end end kw'>end</span>

  <span class='store_location identifier id'>store_location</span>
  <span class='flash identifier id'>flash</span><span class='lbrack token'>[</span><span class='symbol val'>:notice</span><span class='rbrack token'>]</span> <span class='assign token'>=</span> <span class='opts identifier id'>opts</span><span class='lbrack token'>[</span><span class='symbol val'>:flash</span><span class='rbrack token'>]</span>
  <span class='redirect_to identifier id'>redirect_to</span> <span class='opts identifier id'>opts</span><span class='lbrack token'>[</span><span class='symbol val'>:redirect_to</span><span class='rbrack token'>]</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="logged_in?-instance_method">
  
    - (<tt>Object</tt>) <strong>logged_in?</strong> 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>
Returns whether or not there is a currently logged in user
</p>


  </div>
</div>
<div class="tags">
  
</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


69
70
71</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/master_may_i/controller_extensions.rb', line 69</span>

<span class='def def kw'>def</span> <span class='logged_in? fid id'>logged_in?</span>
  <span class='notop op'>!</span><span class='notop op'>!</span> <span class='current_user identifier id'>current_user</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="permission_denied_flash_for_user-instance_method">
  
    - (<tt>Object</tt>) <strong>permission_denied_flash_for_user</strong> 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>
Used by deny_access. Override to customize the flash message displayed to
users who are logged in, but not allowed to access the resource.
</p>


  </div>
</div>
<div class="tags">
  
</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


109
110
111</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/master_may_i/controller_extensions.rb', line 109</span>

<span class='def def kw'>def</span> <span class='permission_denied_flash_for_user identifier id'>permission_denied_flash_for_user</span>
  <span class='string val'>&quot;You don't have permission to access this page.&quot;</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="permission_denied_flash_for_visitor-instance_method">
  
    - (<tt>Object</tt>) <strong>permission_denied_flash_for_visitor</strong> 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>
Used by deny_access. Override to customize the flash message displayed to
visitors who are not yet logged in.
</p>


  </div>
</div>
<div class="tags">
  
</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


115
116
117</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/master_may_i/controller_extensions.rb', line 115</span>

<span class='def def kw'>def</span> <span class='permission_denied_flash_for_visitor identifier id'>permission_denied_flash_for_visitor</span>
  <span class='string val'>&quot;Please login.&quot;</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="permission_denied_redirect_for_user-instance_method">
  
    - (<tt>Object</tt>) <strong>permission_denied_redirect_for_user</strong> 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>
Used by deny_access. Override to customize the URL to which users who are
logged in, but not allowed to access the resource are redirected.
</p>


  </div>
</div>
<div class="tags">
  
</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


121
122
123</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/master_may_i/controller_extensions.rb', line 121</span>

<span class='def def kw'>def</span> <span class='permission_denied_redirect_for_user identifier id'>permission_denied_redirect_for_user</span>
  <span class='root_url identifier id'>root_url</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="permission_denied_redirect_for_visitor-instance_method">
  
    - (<tt>Object</tt>) <strong>permission_denied_redirect_for_visitor</strong> 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>
Used by deny_access. Override to customize the URL to which visitors who
are not logged in are redirected.
</p>


  </div>
</div>
<div class="tags">
  
</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


127
128
129</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/master_may_i/controller_extensions.rb', line 127</span>

<span class='def def kw'>def</span> <span class='permission_denied_redirect_for_visitor identifier id'>permission_denied_redirect_for_visitor</span>
  <span class='login_url identifier id'>login_url</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="redirect_back_or-instance_method">
  
    - (<tt>Object</tt>) <strong>redirect_back_or</strong>(url) 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>
Works in conjunction with store_location. If there is a :return_to set in
the session, redirect the user there. Otherwise, redirect the user to the
given url.
</p>


  </div>
</div>
<div class="tags">
  
</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


140
141
142
143</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/master_may_i/controller_extensions.rb', line 140</span>

<span class='def def kw'>def</span> <span class='redirect_back_or identifier id'>redirect_back_or</span><span class='lparen token'>(</span><span class='url identifier id'>url</span><span class='rparen token'>)</span>
  <span class='redirect_to identifier id'>redirect_to</span><span class='lparen token'>(</span><span class='session identifier id'>session</span><span class='lbrack token'>[</span><span class='symbol val'>:return_to</span><span class='rbrack token'>]</span> <span class='orop op'>||</span> <span class='url identifier id'>url</span><span class='rparen token'>)</span>
  <span class='session identifier id'>session</span><span class='lbrack token'>[</span><span class='symbol val'>:return_to</span><span class='rbrack token'>]</span> <span class='assign token'>=</span> <span class='nil nil kw'>nil</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="require_user-instance_method">
  
    - (<tt>Object</tt>) <strong>require_user</strong> 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>
A before filter which calls deny_access if there isn&#8217;t a currently
logged in user
</p>


  </div>
</div>
<div class="tags">
  
</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


74
75
76</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/master_may_i/controller_extensions.rb', line 74</span>

<span class='def def kw'>def</span> <span class='require_user identifier id'>require_user</span>
  <span class='deny_access identifier id'>deny_access</span> <span class='unless unless_mod kw'>unless</span> <span class='current_user identifier id'>current_user</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <p class="signature " id="store_location-instance_method">
  
    - (<tt>Object</tt>) <strong>store_location</strong> 
  

  
</p><div class="docstring">
  <div class="discussion">
    <p>
Used by deny_access and redirect_back_or to store and later redirect to the
currently requested location
</p>


  </div>
</div>
<div class="tags">
  
</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


133
134
135</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/master_may_i/controller_extensions.rb', line 133</span>

<span class='def def kw'>def</span> <span class='store_location identifier id'>store_location</span>
  <span class='session identifier id'>session</span><span class='lbrack token'>[</span><span class='symbol val'>:return_to</span><span class='rbrack token'>]</span> <span class='assign token'>=</span> <span class='request identifier id'>request</span><span class='dot token'>.</span><span class='request_uri identifier id'>request_uri</span>
<span class='end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
  </div>

</div>
    
    <div id="footer">
  Generated on Fri Dec  4 09:07:16 2009 by 
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool">yard</a>
  0.4.0 (ruby-1.8.6).
</div>

  </body>
</html>